#include <stdio.h>

void QuickSort( int *pData, int left, int right ) 
{

    int i, j;
    int middle, iTemp;
    i = left;
    j = right;
    middle = pData[ ( left + right ) / 2 ];
    do
    {
        while ( ( pData[ i ] > middle ) && ( i < right ) )
            i++;
        while ( ( pData[ j ] < middle ) && ( j > left ) )
            j--;
        if ( i <= j )
        {
            iTemp = pData[ i ];
            pData[ i ] = pData[ j ];
            pData[ j ] = iTemp;
            i++;
            j--;
        }
    } while ( i <= j );
    if( left < j )
        QuickSort( pData, left, j );
    if( right > i )
        QuickSort( pData, i, right );
}

int a[ 1000000 ];

int main( )
{
    int n, m, i;
    while (    scanf("%d%d", &n, &m) != EOF )
    {
        for ( i = 0; i < n; i++ )
            scanf("%d", &a[ i ]);
        QuickSort( a, 0, n - 1 );
        printf("%d", a[ 0 ]);
        for ( i = 1; i < m; i++ )
            printf(" %d", a[ i ]);
        printf("\n");
    }
    return 0;
}
